package com.chenjun.mysite.module.sys.service;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.chenjun.mysite.common.AbstractBaseService;
import com.chenjun.mysite.common.SqlSessionFactoryUtil;
import com.chenjun.mysite.module.sys.entity.User;
import com.chenjun.mysite.module.sys.mapper.IUserMapper;

public class UserService extends AbstractBaseService<User,IUserMapper>
{
	/**
	 * 根据用户名查询User对象
	 * @param user
	 * @return
	 */
	public User findByName(String username)
	{
		SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getInstance();
		SqlSession sqlSession = null;
		User user = null;
		try
		{
			sqlSession = sqlSessionFactory.openSession();
			IUserMapper mapper = sqlSession.getMapper(IUserMapper.class);
			user = mapper.findByName(username);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			sqlSession.close();
		}
		return user;
	}
}
